package com.xsf.pay.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xsf.pay.common.domain.BasePageParam;
import com.xsf.pay.common.domain.ResultData;
import com.xsf.pay.entity.dto.CommonDelDto;
import org.springframework.web.bind.annotation.PostMapping;
import com.xsf.pay.service.UserRoleService;
import com.xsf.pay.entity.UserRole;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import jakarta.annotation.Resource;

/**
 * 用户角色关联表
 *
 * @author makejava
 * @since 2025-05-12 15:09:58
 */
@RestController
@RequestMapping("userRole")
public class UserRoleController {

    @Resource
    private UserRoleService userRoleService;
    
    /**
     * 分页查询
     * @return 返回数据
     */
    @PostMapping("/page")
    public ResultData<Page<UserRole>> page(@RequestBody BasePageParam<UserRole> basePageParam) {
        return ResultData.success(userRoleService.page(basePageParam.getPage()));
    }
    
    /**
     * 新增
     * @return 操作是否成功
     */
    @PostMapping("/insert")
    public ResultData<Object> insert(@RequestBody UserRole userRole) {
        return ResultData.success(userRoleService.save(userRole));
    }

    /**
     * 修改
     * @return 操作是否成功
     */
    @PostMapping("/update")
    public ResultData<Object> update(@RequestBody UserRole userRole) {
        return ResultData.success(userRoleService.updateById(userRole));
    }

    /**
     * 删除
     * @return 操作是否成功
     */
    @PostMapping("/del")
    public ResultData<Object> del(@RequestBody CommonDelDto commonDelDto) {
        return ResultData.success(userRoleService.removeById(commonDelDto.getId()));
    }
}

